package mka.puzzle.draw;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.ArrayList;

import javax.swing.JPanel;

import mka.puzzle.shape.Point;

/**
 * Painter Class. Draw and paint object on Frame.
 * 
 * @version 20131218
 * 
 * @author Nguyenbb
 * 
 */
public class Painter extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3300652607673521098L;

	/**
	 * Dimension of Frame
	 */
	protected int width = 500;
	protected int height = 500;

	/**
	 * Set of Point that draw on Frame
	 */
	private ArrayList<Point> pointList;

	public ArrayList<Point> getPointList() {
		return pointList;
	}

	public void setPointList(ArrayList<Point> pointList) {
		this.pointList = pointList;
	}

	public Painter() {
		this.pointList = new ArrayList<Point>();
	}

	public Painter(ArrayList<Point> list) {
		this.pointList = list;
	}

	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		Graphics2D g2d = (Graphics2D) g;
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		g2d.setColor(new Color(30, 131, 34));
		for (Point p : this.pointList) {
			// g2d.drawOval((int) p.getX(), (int) p.getY(), 0, 0);
			g2d.drawRect((int) p.getX(), (int) p.getY(), 0, 0);
		}
		// g2d.drawOval(200, 300, 200, 200);
		// g2d.drawLine(150, 250, 650, 50);

	}

	/**
	 * getPreferredSize.
	 * 
	 * @return Dimension
	 */
	@Override
	public Dimension getPreferredSize() {
		return new Dimension(this.width, this.height);
	}

	/**
	 * addPoint.
	 * 
	 * @param point
	 *            Point
	 * @return ArrayList<Point>
	 */
	public ArrayList<Point> addPoint(Point point) {
		if (!this.pointList.contains(point))
			this.pointList.add(point);
		return this.pointList;
	}

	/**
	 * addPointList.
	 * 
	 * Add a point of list.
	 * 
	 * @param list
	 *            ArrayList<Point>
	 * @return ArrayList<Point>
	 */
	public ArrayList<Point> addPointList(ArrayList<Point> list) {
		for (Point point : list)
			// if (!this.pointList.contains(point))
			this.pointList.add(point);
		return this.pointList;
	}
}
